<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>客户反馈系统-文章列表</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">

<link href="/ksp/layui/css/layui.css" rel="stylesheet">

<script type="text/javascript" src="/ksp/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/ksp/layui/layui.all.js"></script>
<script type="text/javascript" src="/ksp/js/ksp.com.js"></script>

<script type="text/javascript">
	var element;
	var laypage;

	layui.use(["element", "laypage"], function() {
		element = layui.element;
		laypage = layui.laypage;
	})
	
	function iniBtnFnc() {
		var active = {
				getRec : function() {
					chgBtnBgc("1");
				}
				,getLat : function() {
					chgBtnBgc("2");
				}
				,addTtl : function() {
					window.location.href="/ksp/p/art/artadd";
				}
		};
		
		$(".layui-btn").on("click", function() {
			var type = $(this).data("type");
			active[type] ? active[type].call(this) : "";
		});
	}
	
	function chgBtnBgc(data) {
		if (data == "2") {
			$("#bRec").addClass("layui-btn-primary");
			$("#bLat").removeClass("layui-btn-primary");
			$("#hidTyp").val("ASC");
		} else {
			$("#bRec").removeClass("layui-btn-primary");
			$("#bLat").addClass("layui-btn-primary");
			$("#hidTyp").val("DESC");
		}
		
		qryArtlimit(1, $("#hidTyp").val());
	}
	
	//实现排序，分页查询
	function qryArtlimit(curr, sortyp) {
		var req = {
			 "SOR_TYP" : sortyp 
			,"DTA_PGE" : curr || 1
			,"DTA_LMT" : 20
		};
		
		$.ajax({
			 url : "/ksp/art/KSPA03"
			,type : "post"
			,dataType : "json"
			,data : req
			,success : function(res) {
				var artArr = res.data;
				showArtLst(artArr);
				laypage.render({
					 elem : "page1"
					,count : res.count
					,groups : 5
					,limit : 20
					,skip : true
					,curr : curr || 1
					,jump : function(obj, first) {
						if (!first) {
							qryArtlimit(obj.curr, $("#hidTyp").val())
						}
					}
				});
			}
		});
	}
 	
	//展示数据
	function showArtLst(artArr) {
		var artHtml = '<ul>';
		for (var i = 0; i < artArr.length; i++) {
			var art = artArr[i];
			artHtml += '<li><div><a href="/ksp/p/art/artdta?arttch=' + art.TTL_TCH +'">'
					+ art.TTL_TTL + '</a></div><div>'
					+ art.CRT_USR + '&nbsp;&nbsp;' + art.CRT_TIM
					+ '| <span>浏览量' + art.SCA_CNT +'</span>|<span>留言数' 
					+ art.GOD_CNT + '</span></div><hr></li>';
			
		}
		artHtml += '</ul>';
		$("#divArtLst").html(artHtml);
	}
</script>

<script type="text/javascript">
	$(function() {
		iniNar();
		
		iniBtnFnc();
		
		qryArtlimit(1, "DESC");
		
	});
</script>

</head>
<body>
	<div id="navDiv"></div>
	
	<div style="width: 1000px; padding:10px;">
		<button class="layui-btn" style="width:120px;border:none;"
			data-type="getRec" id="bRec">推荐</button>
		<button class="layui-btn" style="width:120px;border:none;"
			data-type="getLat" id="bLat">最新</button>
		<input type="hidden" id="hidTyp">
		
		<button class="layui-btn" style="width:120px;float:right;"
			data-type="addTtl">发表主题</button>
			
		<div style="padding-left:40px;padding-top:20px;">
			<div id="divArtLst">
				<ul>
					<li>
						<div><a href="/ksp/p/art/artdta?arttch=">标题</a></div>
						<div>
							发表人 发表时间 <span>浏览量</span>|<span >留言数量</span>
						</div>
						<hr>
					</li>
					<li>
						<div><a href="/ksp/p/art/artdta?arttch=">标题</a></div>
						<div>
							发表人 发表时间 <span>浏览量</span>|<span >留言数量</span>
						</div>
						<hr>
					</li>
					<li>
						<div><a href="/ksp/p/art/artdta?arttch=">标题</a></div>
						<div>
							发表人 发表时间 <span>浏览量</span>|<span >留言数量</span>
						</div>
						<hr>
					</li>
				</ul>
			</div>
			
			<!-- 分页插件 -->
			<div>
				<div id="page1"></div>
			</div>
		</div>
	</div>
</body>
</html>